#include<bits/stdc++.h>
using namespace std;
double calc(double V,double v,double a){
  return (V*V-v*v)/(2*a);
}
const double Exp=0.00001;
int main(){
  freopen("detect.in","r",stdin);
  freopen("detect.out","w",stdout);
  int t;
  cin>>t;
  while(t--){
    int n,m,L,ans1=0;
    double V;
    cin>>n>>m>>L>>V;
    double l[n+1],r[n+1];
    int lid[n+1],rid[n+1];
    memset(lid,INT_MAX,sizeof(lid));
    memset(rid,0,sizeof(rid));
    for(int i=1;i<=n;i++){
      double d,v,g;
      cin>>d>>v>>g;
      if(g<=0&&v<=V)
        l[i]=-1,r[i]=-1;
      if(g>=0&&v>V)
        l[i]=d,r[i]=L;
      if(g>0&&v<=V){
        double S=d+calc(V,v,g);
        if(S<=L)
          l[i]=S+Exp,r[i]=L;
        else
          l[i]=-1,r[i]=-1;
      }
      if(g<0&&v>V){
        double S=d+calc(V,v,g);
        if(S>L)
          l[i]=d,r[i]=L;
        else
          l[i]=d,r[i]=S-Exp;
      }
    }
    int p[m+1];
    bool mk[n+1]={false};
    for(int i=1;i<=m;i++){
      cin>>p[i];
      for(int j=1;j<=n;j++)
        if(l[j]<=p[i]&&r[j]>=p[i]&&!mk[j])
          mk[j]=1,ans1++;
    }
    printf("%d %d\n",ans1,ans1/2+2);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
